/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flgrCoreMalloc.h"
#include "flgrCoreData.h"
#include "flgrCoreCopy.h"
#include "flgrCoreDispatch.h"
#include "flgrCoreDataIO.h"

/*!
 * \defgroup group_fulguro_core_copy Copy functions
 * \ingroup group_fulguro_core
 * \brief Functions to copy FLGR_Data2D
 * @{
 */

#define BVSZ (8*sizeof(fgBIT))

#define FLGR_MACRO_COPY1D_SAME_TYPE					\
  memcpy(datdest->array, datsrc->array, (datdest->bps*datdest->length*datdest->spp)/8)

#define FLGR_MACRO_COPY1D_BIT						\
  memcpy(datdest->array,datsrc->array,( ( ((datdest->length*datdest->spp) / BVSZ) + 1) * BVSZ ) / 8 )


#define FLGR_MACRO_COPY1D(dtypeDest, dtypeSrc)			\
  int j,length = datdest->length*datdest->spp;			\
  dtypeDest var;						\
  dtypeDest *dar = (dtypeDest *) datdest->array;		\
  dtypeSrc *sar = (dtypeSrc *) datsrc->array;			\
								\
  FLGR_DECLARE_FUNCTION;					\
								\
  for(j=0; j<length ; j++) {					\
    var = (dtypeDest) flgr1d_get_data_array_##dtypeSrc(sar,j);	\
    flgr1d_set_data_array_##dtypeDest(dar,j,var);		\
  }								\
  return

#define FLGR_MACRO_COPY1D_BIT_DTYPE(dtypeSrc)			\
  int j,k;							\
  int bps = sizeof(fgBIT)<<3;					\
  int mlength = (datdest->length*datdest->spp) % bps;		\
  int length = (datdest->length*datdest->spp) - mlength;	\
  dtypeSrc *psrc;						\
  fgBIT *pdest;							\
  fgBIT bitval=0;						\
  fgBIT word = 0;						\
  FLGR_DECLARE_FUNCTION;					\
								\
								\
  psrc = (dtypeSrc*) datsrc->array;				\
  pdest = (fgBIT*) datdest->array;				\
  j=0;								\
								\
  while(j<length) {						\
    word=0;							\
    for(k=0 ; k<bps ; k++) {					\
      bitval = ((psrc[j++]!=0) ? 1 : 0);			\
      word = (word<<1) | bitval;				\
    }								\
    *pdest++=word;						\
  }								\
								\
  word=0;							\
  for(k=0;k<mlength;k++) {					\
    bitval = ((psrc[j++]!=0) ? 1 : 0);				\
    word = (word<<1) | bitval;					\
  }								\
  if(mlength!=0)						\
    *pdest++=word<<(bps-mlength);				\
								\
  return

#define FLGR_MACRO_COPY1D_DTYPE_BIT(dtypeDest)			\
  int j,k;							\
  int bps = sizeof(fgBIT)<<3;					\
  int mlength = (datdest->length*datdest->spp) % bps;		\
  int length = (datdest->length*datdest->spp) - mlength;	\
  dtypeDest *pdest;						\
  fgBIT *psrc;							\
  fgBIT word = 0;						\
  fgBIT carry = ((fgBIT) 1)<<(bps-1);				\
  FLGR_DECLARE_FUNCTION;					\
								\
								\
  psrc = (fgBIT*) datsrc->array;				\
  pdest = (dtypeDest*) datdest->array;				\
  j=0;								\
								\
  while(j<length) {						\
    word = *psrc++;						\
    for(k=0 ; k<bps ; k++) {					\
      pdest[j++]=(dtypeDest) ((word & carry)>>(bps-1));		\
      word = word <<1;						\
    }								\
  }								\
								\
  word = *psrc;							\
  for(k=0 ; k<mlength ; k++) {					\
    pdest[j++]=(dtypeDest) ((word & carry)>>(bps-1));		\
    word = word <<1;						\
  }								\
  return




void flgr1d_copy_fgBIT_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT;
}
void flgr1d_copy_fgUINT8_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgUINT8);
}
void flgr1d_copy_fgUINT16_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgUINT16);
}
void flgr1d_copy_fgUINT32_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgUINT32);
}
void flgr1d_copy_fgINT8_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgINT8);
}
void flgr1d_copy_fgINT16_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgINT16);
}
void flgr1d_copy_fgINT32_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgINT32);
}
void flgr1d_copy_fgFLOAT32_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgFLOAT32);
}
void flgr1d_copy_fgFLOAT64_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_DTYPE_BIT(fgFLOAT64);
}




void flgr1d_copy_fgBIT_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgUINT8);
}
void flgr1d_copy_fgUINT8_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgUINT16_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgUINT8);
}
void flgr1d_copy_fgUINT32_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgUINT8);
}
void flgr1d_copy_fgINT8_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgUINT8);
}
void flgr1d_copy_fgINT16_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgUINT8);
}
void flgr1d_copy_fgINT32_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgUINT8);
}
void flgr1d_copy_fgFLOAT32_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgUINT8);
}
void flgr1d_copy_fgFLOAT64_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgUINT8);
}




void flgr1d_copy_fgBIT_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgUINT16);
}
void flgr1d_copy_fgUINT8_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgUINT16);
}
void flgr1d_copy_fgUINT16_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgUINT32_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgUINT16);
}
void flgr1d_copy_fgINT8_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgUINT16);
}
void flgr1d_copy_fgINT16_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgUINT16);
}
void flgr1d_copy_fgINT32_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgUINT16);
}
void flgr1d_copy_fgFLOAT32_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgUINT16);
}
void flgr1d_copy_fgFLOAT64_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgUINT16);
}




void flgr1d_copy_fgBIT_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgUINT32);
}
void flgr1d_copy_fgUINT8_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgUINT32);
}
void flgr1d_copy_fgUINT16_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgUINT32);
}
void flgr1d_copy_fgUINT32_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgINT8_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgUINT32);
}
void flgr1d_copy_fgINT16_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgUINT32);
}
void flgr1d_copy_fgINT32_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgUINT32);
}
void flgr1d_copy_fgFLOAT32_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgUINT32);
}
void flgr1d_copy_fgFLOAT64_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgUINT32);
}




void flgr1d_copy_fgBIT_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgINT8);
}
void flgr1d_copy_fgUINT8_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgINT8);
}
void flgr1d_copy_fgUINT16_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgINT8);
}
void flgr1d_copy_fgUINT32_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgINT8);
}
void flgr1d_copy_fgINT8_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgINT16_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgINT8);
}
void flgr1d_copy_fgINT32_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgINT8);
}
void flgr1d_copy_fgFLOAT32_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgINT8);
}
void flgr1d_copy_fgFLOAT64_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgINT8);
}




void flgr1d_copy_fgBIT_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgINT16);
}
void flgr1d_copy_fgUINT8_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgINT16);
}
void flgr1d_copy_fgUINT16_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgINT16);
}
void flgr1d_copy_fgUINT32_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgINT16);
}
void flgr1d_copy_fgINT8_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgINT16);
}
void flgr1d_copy_fgINT16_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgINT32_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgINT16);
}
void flgr1d_copy_fgFLOAT32_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgINT16);
}
void flgr1d_copy_fgFLOAT64_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgINT16);
}




void flgr1d_copy_fgBIT_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgINT32);
}
void flgr1d_copy_fgUINT8_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgINT32);
}
void flgr1d_copy_fgUINT16_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgINT32);
}
void flgr1d_copy_fgUINT32_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgINT32);
}
void flgr1d_copy_fgINT8_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgINT32);
}
void flgr1d_copy_fgINT16_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgINT32);
}
void flgr1d_copy_fgINT32_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgFLOAT32_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgINT32);
}
void flgr1d_copy_fgFLOAT64_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgINT32);
}




void flgr1d_copy_fgBIT_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgFLOAT32);
}
void flgr1d_copy_fgUINT8_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgFLOAT32);
}
void flgr1d_copy_fgUINT16_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgFLOAT32);
}
void flgr1d_copy_fgUINT32_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgFLOAT32);
}
void flgr1d_copy_fgINT8_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgFLOAT32);
}
void flgr1d_copy_fgINT16_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgFLOAT32);
}
void flgr1d_copy_fgINT32_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgFLOAT32);
}
void flgr1d_copy_fgFLOAT32_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}
void flgr1d_copy_fgFLOAT64_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT64,fgFLOAT32);
}




void flgr1d_copy_fgBIT_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_BIT_DTYPE(fgFLOAT64);
}
void flgr1d_copy_fgUINT8_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT8,fgFLOAT64);
}
void flgr1d_copy_fgUINT16_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT16,fgFLOAT64);
}
void flgr1d_copy_fgUINT32_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgUINT32,fgFLOAT64);
}
void flgr1d_copy_fgINT8_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT8,fgFLOAT64);
}
void flgr1d_copy_fgINT16_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT16,fgFLOAT64);
}
void flgr1d_copy_fgINT32_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgINT32,fgFLOAT64);
}
void flgr1d_copy_fgFLOAT32_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D(fgFLOAT32,fgFLOAT64);
}
void flgr1d_copy_fgFLOAT64_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_COPY1D_SAME_TYPE;
}





//////////////////////////////////////////////////////////////////
// Macro for copying considering a fix type for source
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_COPY1D_SRC_FIX_TYPE(dtype_src,dtype1,dtype2,		\
				       dtype3,dtype4,dtype5,dtype6,	\
				       dtype7,dtype8,dtype9)		\
									\
  if(flgr1d_data_is_type_##dtype1(datdest)) {				\
    flgr1d_copy_##dtype1##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype2(datdest)) {			\
    flgr1d_copy_##dtype2##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype3(datdest)) {			\
    flgr1d_copy_##dtype3##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype4(datdest)) {			\
    flgr1d_copy_##dtype4##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype5(datdest)) {			\
    flgr1d_copy_##dtype5##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype6(datdest)) {			\
    flgr1d_copy_##dtype6##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype7(datdest)) {			\
    flgr1d_copy_##dtype7##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype8(datdest)) {			\
    flgr1d_copy_##dtype8##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr1d_data_is_type_##dtype9(datdest)) {			\
    flgr1d_copy_##dtype9##_##dtype_src( datdest , datsrc);		\
									\
  }else error=1



//////////////////////////////////////////////////////////////////
/*! Copy FLGR_Data1D source array to FLGR_Data1D destination array
 *
 *  - FLGR_Data1D must have the same size (size_x and size_y)
 *  - FLGR_Data1D types could be differents but no normalization are performed
 *
 *  @param *datdest : pointer to FLGR_Data1D structure
 *  @param *datsrc : pointer to FLGR_Data1D structure
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_copy(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  int error=0;
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;


  if((datdest==NULL) || (datsrc==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if((ret=flgr1d_is_data_same_length(datdest, datsrc))!=FLGR_RET_OK) {
    POST_ERROR("src and dest dat have different length !\n");
    return ret;
  }

  if(datdest->spp != datdest->spp) {
    POST_ERROR("Sample per pixel are different\n");
    return ret;
  }

  if(datsrc->type==FLGR_UINT8) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgUINT8,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_UINT16) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgUINT16,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_UINT32) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgUINT32,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_INT8) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgINT8,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_INT16) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgINT16,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_INT32) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgINT32,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_FLOAT32) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgFLOAT32,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_FLOAT64) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgFLOAT64,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_BIT) {
    FLGR_MACRO_COPY1D_SRC_FIX_TYPE(fgBIT,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else {
    error=1;
  }

  if(error==1) {
    POST_ERROR("dest data type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }

  return FLGR_RET_OK;

}


















#define FLGR_MACRO_COPY2D(dtypeDest, dtypeSrc)			\
  int i;							\
  FLGR_Data1D **dest = datdest->row;				\
  FLGR_Data1D **src = datsrc->row;				\
								\
  FLGR_DECLARE_FUNCTION;					\
								\
  for(i=0;i<datsrc->size_y;i++) {				\
    flgr1d_copy_##dtypeDest##_##dtypeSrc(dest[i],src[i]);	\
  }								\
  return


void flgr2d_copy_fgBIT_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgBIT);
}
void flgr2d_copy_fgUINT8_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgBIT);
}
void flgr2d_copy_fgUINT16_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgBIT);
}
void flgr2d_copy_fgUINT32_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgBIT);
}
void flgr2d_copy_fgINT8_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgBIT);
}
void flgr2d_copy_fgINT16_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgBIT);
}
void flgr2d_copy_fgINT32_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgBIT);
}
void flgr2d_copy_fgFLOAT32_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgBIT);
}
void flgr2d_copy_fgFLOAT64_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgBIT);
}




void flgr2d_copy_fgBIT_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgUINT8);
}
void flgr2d_copy_fgUINT8_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgUINT8);
}
void flgr2d_copy_fgUINT16_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgUINT8);
}
void flgr2d_copy_fgUINT32_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgUINT8);
}
void flgr2d_copy_fgINT8_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgUINT8);
}
void flgr2d_copy_fgINT16_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgUINT8);
}
void flgr2d_copy_fgINT32_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgUINT8);
}
void flgr2d_copy_fgFLOAT32_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgUINT8);
}
void flgr2d_copy_fgFLOAT64_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgUINT8);
}




void flgr2d_copy_fgBIT_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgUINT16);
}
void flgr2d_copy_fgUINT8_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgUINT16);
}
void flgr2d_copy_fgUINT16_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgUINT16);
}
void flgr2d_copy_fgUINT32_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgUINT16);
}
void flgr2d_copy_fgINT8_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgUINT16);
}
void flgr2d_copy_fgINT16_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgUINT16);
}
void flgr2d_copy_fgINT32_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgUINT16);
}
void flgr2d_copy_fgFLOAT32_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgUINT16);
}
void flgr2d_copy_fgFLOAT64_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgUINT16);
}






void flgr2d_copy_fgBIT_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgUINT32);
}
void flgr2d_copy_fgUINT8_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgUINT32);
}
void flgr2d_copy_fgUINT16_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgUINT32);
}
void flgr2d_copy_fgUINT32_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgUINT32);
}
void flgr2d_copy_fgINT8_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgUINT32);
}
void flgr2d_copy_fgINT16_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgUINT32);
}
void flgr2d_copy_fgINT32_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgUINT32);
}
void flgr2d_copy_fgFLOAT32_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgUINT32);
}
void flgr2d_copy_fgFLOAT64_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgUINT32);
}





void flgr2d_copy_fgBIT_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgINT8);
}
void flgr2d_copy_fgUINT8_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgINT8);
}
void flgr2d_copy_fgUINT16_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgINT8);
}
void flgr2d_copy_fgUINT32_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgINT8);
}
void flgr2d_copy_fgINT8_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgINT8);
}
void flgr2d_copy_fgINT16_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgINT8);
}
void flgr2d_copy_fgINT32_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgINT8);
}
void flgr2d_copy_fgFLOAT32_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgINT8);
}
void flgr2d_copy_fgFLOAT64_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgINT8);
}




void flgr2d_copy_fgBIT_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgINT16);
}
void flgr2d_copy_fgUINT8_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgINT16);
}
void flgr2d_copy_fgUINT16_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgINT16);
}
void flgr2d_copy_fgUINT32_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgINT16);
}
void flgr2d_copy_fgINT8_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgINT16);
}
void flgr2d_copy_fgINT16_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgINT16);
}
void flgr2d_copy_fgINT32_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgINT16);
}
void flgr2d_copy_fgFLOAT32_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgINT16);
}
void flgr2d_copy_fgFLOAT64_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgINT16);
}






void flgr2d_copy_fgBIT_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgINT32);
}
void flgr2d_copy_fgUINT8_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgINT32);
}
void flgr2d_copy_fgUINT16_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgINT32);
}
void flgr2d_copy_fgUINT32_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgINT32);
}
void flgr2d_copy_fgINT8_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgINT32);
}
void flgr2d_copy_fgINT16_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgINT32);
}
void flgr2d_copy_fgINT32_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgINT32);
}
void flgr2d_copy_fgFLOAT32_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgINT32);
}
void flgr2d_copy_fgFLOAT64_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgINT32);
}








void flgr2d_copy_fgBIT_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgFLOAT32);
}
void flgr2d_copy_fgUINT8_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgFLOAT32);
}
void flgr2d_copy_fgUINT16_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgFLOAT32);
}
void flgr2d_copy_fgUINT32_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgFLOAT32);
}
void flgr2d_copy_fgINT8_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgFLOAT32);
}
void flgr2d_copy_fgINT16_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgFLOAT32);
}
void flgr2d_copy_fgINT32_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgFLOAT32);
}
void flgr2d_copy_fgFLOAT32_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgFLOAT32);
}
void flgr2d_copy_fgFLOAT64_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgFLOAT32);
}




void flgr2d_copy_fgBIT_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgBIT,fgFLOAT64);
}
void flgr2d_copy_fgUINT8_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT8,fgFLOAT64);
}
void flgr2d_copy_fgUINT16_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT16,fgFLOAT64);
}
void flgr2d_copy_fgUINT32_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgUINT32,fgFLOAT64);
}
void flgr2d_copy_fgINT8_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT8,fgFLOAT64);
}
void flgr2d_copy_fgINT16_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT16,fgFLOAT64);
}
void flgr2d_copy_fgINT32_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgINT32,fgFLOAT64);
}
void flgr2d_copy_fgFLOAT32_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT32,fgFLOAT64);
}
void flgr2d_copy_fgFLOAT64_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_COPY2D(fgFLOAT64,fgFLOAT64);
}





//////////////////////////////////////////////////////////////////
// Macro for copying considering a fix type for source
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_COPY2D_SRC_FIX_TYPE(dtype_src,dtype1,dtype2,		\
				       dtype3,dtype4,dtype5,dtype6,	\
				       dtype7,dtype8,dtype9)		\
									\
  if(flgr2d_data_is_type_##dtype1(datdest)) {				\
    flgr2d_copy_##dtype1##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype2(datdest)) {			\
    flgr2d_copy_##dtype2##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype3(datdest)) {			\
    flgr2d_copy_##dtype3##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype4(datdest)) {			\
    flgr2d_copy_##dtype4##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype5(datdest)) {			\
    flgr2d_copy_##dtype5##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype6(datdest)) {			\
    flgr2d_copy_##dtype6##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype7(datdest)) {			\
    flgr2d_copy_##dtype7##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype8(datdest)) {			\
    flgr2d_copy_##dtype8##_##dtype_src( datdest , datsrc);		\
									\
  }else if(flgr2d_data_is_type_##dtype9(datdest)) {			\
    flgr2d_copy_##dtype9##_##dtype_src( datdest , datsrc);		\
									\
  }else error=1

//////////////////////////////////////////////////////////////////
/*! Copy FLGR_Data2D source array to FLGR_Data2D destination array
 *
 *  - FLGR_Data2D must have the same size (size_x and size_y)
 *  - FLGR_Data2D types could be differents but no normalization are performed
 *
 *  @param *datdest : pointer to FLGR_Data2D structure
 *  @param *datsrc : pointer to FLGR_Data2D structure
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_copy(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  int error=0;
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((datdest==NULL) || (datsrc==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if((ret=flgr2d_is_data_same_size(datsrc, datdest))!=FLGR_RET_OK) {
    POST_ERROR("src and dest dat have different size !\n");
    return ret;
  }

  if(datsrc->type==FLGR_UINT8) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgUINT8,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_UINT16) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgUINT16,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_UINT32) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgUINT32,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_INT8) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgINT8,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_INT16) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgINT16,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_INT32) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgINT32,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_FLOAT32) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgFLOAT32,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_FLOAT64) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgFLOAT64,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else if(datsrc->type==FLGR_BIT) {
    FLGR_MACRO_COPY2D_SRC_FIX_TYPE(fgBIT,fgBIT,fgUINT8,fgUINT16,fgUINT32,
				   fgINT8,fgINT16,fgINT32,fgFLOAT32,fgFLOAT64);

  }else {
    error=1;
  }

  if(error==1) {
    POST_ERROR("dest data type unknown!\n");
    return FLGR_RET_TYPE_UNKNOWN;
  }

  return FLGR_RET_OK;

}









void flgr1d_import_raw_fgBIT(FLGR_Data1D *datdest, void* raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgBIT*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_BIT_DTYPE(fgBIT);
  }
}

void flgr1d_import_raw_fgUINT8(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgUINT8*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgUINT16(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgUINT16*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgUINT32(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgUINT32*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgINT8(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgINT8*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgINT16(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgINT16*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgINT32(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgINT32*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgFLOAT32(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgFLOAT32*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_import_raw_fgFLOAT64(FLGR_Data1D *datdest, void *raw) {
  FLGR_Data1D datsrc[1];
  FLGR_DECLARE_FUNCTION;

  datsrc->bps=datdest->bps;
  datsrc->spp=datdest->spp;
  datsrc->length=datdest->length;
  datsrc->array=(fgFLOAT64*)raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

//////////////////////////////////////////////////////////////////
/*! Import a raw in a FLGR_Data1D. The raw is read using type of the given FLGR_Data1D
 *  @param datdest : a pointer to FLGR_Data1D
 *  @param raw   : a pointer to the array (the type of the array must fit with the type of dat->type)
 *  @returns FLGR_RET_OK, ...
 *
 *  For fgBIT, raw are stored one pixel (one bit) by fgBIT memory cell contrary to FLGR_DataXD where there is
 *  32 bits per fgBIT memory cell
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_import_raw_ptr(FLGR_Data1D *datdest, void* raw) {
  FLGR_DECLARE_FUNCTION;

  if((datdest==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr1d_import_raw,datdest,raw);
}








void flgr1d_export_raw_fgBIT(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgBIT*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_DTYPE_BIT(fgBIT);
  }
}

void flgr1d_export_raw_fgUINT8(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgUINT8*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgUINT16(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgUINT16*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgUINT32(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgUINT32*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgINT8(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgINT8*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgINT16(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgINT16*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgINT32(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgINT32*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgFLOAT32(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgFLOAT32*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

void flgr1d_export_raw_fgFLOAT64(void *raw, FLGR_Data1D *datsrc) {
  FLGR_Data1D datdest[1];
  FLGR_DECLARE_FUNCTION;

  datdest->bps=datsrc->bps;
  datdest->spp=datsrc->spp;
  datdest->length=datsrc->length;
  datdest->array=(fgFLOAT64*) raw;

  if(raw!=NULL) {
    FLGR_MACRO_COPY1D_SAME_TYPE;
  }
}

//////////////////////////////////////////////////////////////////
/*! Export FLGR_Data1D to a raw. The raw is stored using type of the given FLGR_Data1D
 *  @param raw   : a pointer to the array (the type of the array must fit with the type of dat->type)
 *  @param datsrc : a pointer to FLGR_Data1D
 *  @returns FLGR_RET_OK, ...
 *
 *  For fgBIT, raw are stored one pixel (one bit) by fgBIT memory cell contrary to FLGR_DataXD where there is
 *  32 bits per fgBIT memory cell
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_export_raw_ptr(void* raw, FLGR_Data1D *datsrc) {
  FLGR_DECLARE_FUNCTION;

  if((datsrc==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr1d_export_raw,raw,datsrc);
}












////////////////////////////////////////////////////////////////////////////
// Macro for different type of set_datafromRaw
////////////////////////////////////////////////////////////////////////////
#define FLGR_MACRO_IMPORT2D_RAW(dtype)			\
  FLGR_Data1D **dest = datdest->row;			\
  int spp = datdest->spp;				\
  int size = (datdest->size_x*sizeof(dtype)*spp);	\
  int i;						\
							\
  FLGR_DECLARE_FUNCTION;				\
							\
  for(i=0 ; i < datdest->size_y ; i++) {		\
    flgr1d_import_raw_##dtype(dest[i],raw);		\
    raw += size;					\
  }							\
  return


void flgr2d_import_raw_fgBIT(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgBIT);
}
void flgr2d_import_raw_fgUINT8(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgUINT8);
}
void flgr2d_import_raw_fgUINT16(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgUINT16);
}
void flgr2d_import_raw_fgUINT32(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgUINT32);
}
void flgr2d_import_raw_fgINT8(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgINT8);
}
void flgr2d_import_raw_fgINT16(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgINT16);
}
void flgr2d_import_raw_fgINT32(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgINT32);
}
void flgr2d_import_raw_fgFLOAT32(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgFLOAT32);
}
void flgr2d_import_raw_fgFLOAT64(FLGR_Data2D *datdest, void* raw) {
  FLGR_MACRO_IMPORT2D_RAW(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Import a raw in a FLGR_Data2D. The raw is read using type of the given FLGR_Data2D
 *  @param datdest   : a pointer to FLGR_Data2D
 *  @param raw   : a pointer to the array (the type of the array must fit with the type of dat->type)
 *  @returns FLGR_RET_OK, ...
 *
 *  For fgBIT, raw are stored one pixel (one bit) by fgBIT memory cell contrary to FLGR_DataXD where there is
 *  32 bits per fgBIT memory cell
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_import_raw_ptr(FLGR_Data2D *datdest, void* raw) {
  FLGR_DECLARE_FUNCTION;

  if((datdest==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_import_raw,datdest,raw);
}





////////////////////////////////////////////////////////////////////////////
// Macro for different type of set_datafromRaw
////////////////////////////////////////////////////////////////////////////
#define FLGR_MACRO_EXPORT2D_RAW(dtype)			\
  FLGR_Data1D **src = datsrc->row;			\
  int spp = datsrc->spp;				\
  int size = (datsrc->size_x*sizeof(dtype)*spp);	\
  int i;						\
							\
  FLGR_DECLARE_FUNCTION;				\
							\
  for(i=0 ; i < datsrc->size_y ; i++) {			\
    flgr1d_export_raw_##dtype(raw,src[i]);		\
    raw += size;					\
  }							\
  return


void flgr2d_export_raw_fgBIT(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgBIT);
}
void flgr2d_export_raw_fgUINT8(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgUINT8);
}
void flgr2d_export_raw_fgUINT16(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgUINT16);
}
void flgr2d_export_raw_fgUINT32(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgUINT32);
}
void flgr2d_export_raw_fgINT8(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgINT8);
}
void flgr2d_export_raw_fgINT16(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgINT16);
}
void flgr2d_export_raw_fgINT32(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgINT32);
}
void flgr2d_export_raw_fgFLOAT32(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgFLOAT32);
}
void flgr2d_export_raw_fgFLOAT64(void* raw, FLGR_Data2D *datsrc) {
  FLGR_MACRO_EXPORT2D_RAW(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! Export FLGR_Data2D. The raw is stored using type of the given FLGR_Data2D
 *  @param raw   : a pointer to the array (the type of the array must fit with the type of dat->type)
 *  @param datsrc : a pointer to FLGR_Data2D
 *  @returns FLGR_RET_OK, ...
 *
 *  For fgBIT, raw are stored one pixel (one bit) by fgBIT memory cell contrary to FLGR_DataXD where there is
 *  32 bits per fgBIT memory cell
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_export_raw_ptr(void* raw, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;

  if((datsrc==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr2d_export_raw,raw, datsrc);
}




void flgr2d_copy_to_1d_fgBIT(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  int i,j,k,m=0;
  fgBIT val;

  FLGR_DECLARE_FUNCTION;

  for(i=0 ; i<datsrc->size_y ; i++) {
    for(j=0 ; j<datsrc->size_x ; j++) {
      for(k=0 ; k<datsrc->spp ; k++) {
	val = flgr_get_array_fgBIT((fgBIT*) datsrc->array[i],j);
	flgr_set_array_fgBIT((fgBIT*) datdest->array,m,val);
	m++;
      }
    }
  }
}
void flgr2d_copy_to_1d_fgUINT8(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgUINT8(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgUINT16(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgUINT16(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgUINT32(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgUINT32(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgINT8(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgINT8(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgINT16(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgINT16(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgINT32(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgINT32(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgFLOAT32(datdest->array,datsrc);
}
void flgr2d_copy_to_1d_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  flgr2d_export_raw_fgFLOAT64(datdest->array,datsrc);
}
//////////////////////////////////////////////////////////////////
/*! copy 2d data to 1d data
 *  @param datdest : a pointer to FLGR_Data1D
 *  @param datsrc  : a pointer to FLGR_Data2D
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_copy_to_1d(FLGR_Data1D *datdest, FLGR_Data2D *datsrc) {
  FLGR_DECLARE_FUNCTION;

  if((datsrc==NULL) || (datdest==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(datdest->length != (datsrc->size_y*datsrc->size_x)) {
    POST_ERROR("data1d too small\n");
    return FLGR_RET_SIZE_ERROR;
  }

  if(datdest->type != datdest->type) {
    POST_ERROR("type are different\n");
    return FLGR_RET_TYPE_DIFFERENT;
  }

  if(datdest->spp != datdest->spp) {
    POST_ERROR("spp are different\n");
    return FLGR_RET_VECTOR_SIZE_DIFFERENT;
  }

  FLGR_DISPATCH_PROCEDURE(datsrc->type, flgr2d_copy_to_1d, datdest, datsrc);
}



void flgr1d_copy_to_2d_fgBIT(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  int i,j,k,m=0;
  fgBIT val;

  FLGR_DECLARE_FUNCTION;

  for(i=0 ; i<datdest->size_y ; i++) {
    for(j=0 ; j<datdest->size_x ; j++) {
      for(k=0 ; k<datdest->spp ; k++) {
	val = flgr_get_array_fgBIT((fgBIT*) datsrc->array,j);
	flgr_set_array_fgBIT((fgBIT*) datdest->array[i],m,val);
	m++;
      }
    }
  }
}
void flgr1d_copy_to_2d_fgUINT8(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgUINT8(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgUINT16(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgUINT16(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgUINT32(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgUINT32(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgINT8(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgINT8(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgINT16(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgINT16(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgINT32(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgINT32(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgFLOAT32(datdest,datsrc->array);
}
void flgr1d_copy_to_2d_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  flgr2d_import_raw_fgFLOAT64(datdest,datsrc->array);
}
//////////////////////////////////////////////////////////////////
/*! copy 1d data to 2d data
 *  @param datdest : a pointer to FLGR_Data1D
 *  @param datsrc  : a pointer to FLGR_Data2D
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_copy_to_2d(FLGR_Data2D *datdest, FLGR_Data1D *datsrc) {
  FLGR_DECLARE_FUNCTION;

  if((datsrc==NULL) || (datdest==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if(datsrc->length != (datdest->size_y*datdest->size_x)) {
    POST_ERROR("data1d too small\n");
    return FLGR_RET_SIZE_ERROR;
  }

  if(datdest->type != datdest->type) {
    POST_ERROR("type are different\n");
    return FLGR_RET_TYPE_DIFFERENT;
  }

  if(datdest->spp != datdest->spp) {
    POST_ERROR("spp are different\n");
    return FLGR_RET_VECTOR_SIZE_DIFFERENT;
  }

  FLGR_DISPATCH_PROCEDURE(datsrc->type, flgr1d_copy_to_2d, datdest, datsrc);
}





//////////////////////////////////////////////////////////////////
// macro for flgr1d_mirror
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_MIRROR1D(dtype)			\
  FLGR_Vector *vec1;					\
  int i,k;						\
							\
  FLGR_DECLARE_FUNCTION;				\
							\
  vec1 = flgr_vector_create(datsrc->spp,datsrc->type);	\
  							\
  for(i=0,k=datsrc->length-1 ; k >= 0 ; k--,i++) {	\
    flgr1d_get_data_vector_##dtype(datsrc,i,vec1);	\
    flgr1d_set_data_vector_##dtype(datdest,k,vec1);	\
  }							\
  							\
  flgr_vector_destroy(vec1);				\
  return

void flgr1d_mirror_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgBIT);
}
void flgr1d_mirror_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgUINT8);
}
void flgr1d_mirror_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgUINT16);
}
void flgr1d_mirror_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgUINT32);
}
void flgr1d_mirror_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgINT8);
}
void flgr1d_mirror_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgINT16);
}
void flgr1d_mirror_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgINT32);
}
void flgr1d_mirror_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgFLOAT32);
}
void flgr1d_mirror_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_MACRO_MIRROR1D(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! mirror signal (obviously horizontally, ...)
 *  @param datdest : a pointer to FLGR_Data1D
 *  @param datsrc  : a pointer to FLGR_Data1D
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_mirror(FLGR_Data1D *datdest, FLGR_Data1D *datsrc) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((datdest == NULL) || (datsrc == NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  ret = flgr1d_is_data_same_attributes(datdest, datsrc, __FUNCTION__);
  if(ret != FLGR_RET_OK) return ret;
  

  FLGR_DISPATCH_PROCEDURE(datdest->type, flgr1d_mirror, datdest, datsrc);
}






//////////////////////////////////////////////////////////////////
// macro for flgr1d_mirror_hmorph
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_MIRROR1D_HMORPH(dtype)		\
  FLGR_Data1D *datdest = flgr1d_create_from(dat);	\
							\
  FLGR_DECLARE_FUNCTION;				\
							\
  flgr1d_mirror_##dtype(datdest,dat);			\
  flgr1d_copy_##dtype##_##dtype(dat,datdest);		\
  flgr1d_destroy(datdest);				\
							\
  return

void flgr1d_mirror_hmorph_fgBIT(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgBIT);
}
void flgr1d_mirror_hmorph_fgUINT8(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgUINT8);
}
void flgr1d_mirror_hmorph_fgUINT16(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgUINT16);
}
void flgr1d_mirror_hmorph_fgUINT32(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgUINT32);
}
void flgr1d_mirror_hmorph_fgINT8(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgINT8);
}
void flgr1d_mirror_hmorph_fgINT16(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgINT16);
}
void flgr1d_mirror_hmorph_fgINT32(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgINT32);
}
void flgr1d_mirror_hmorph_fgFLOAT32(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgFLOAT32);
}
void flgr1d_mirror_hmorph_fgFLOAT64(FLGR_Data1D *dat) {
  FLGR_MACRO_MIRROR1D_HMORPH(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! mirror signal (obviously horizontally, ...)
 *  @param dat : a pointer to FLGR_Data1D
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr1d_mirror_hmorph(FLGR_Data1D *dat) {
  FLGR_DECLARE_FUNCTION;

  if(dat == NULL) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_DISPATCH_PROCEDURE(dat->type, flgr1d_mirror_hmorph, dat);
}












//////////////////////////////////////////////////////////////////
// macro for flgr2d_mirror_horizontal
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_MIRROR2D_HORIZONTAL(dtype)		\
  FLGR_Vector *vec1;					\
  int i,j,k;						\
							\
  FLGR_DECLARE_FUNCTION;				\
							\
  vec1 = flgr_vector_create(datsrc->spp,datsrc->type);	\
  							\
  for(i=0 ; i < datsrc->size_y ; i++) {			\
    for(j=0,k=datsrc->size_x-1 ; k >= 0 ; k--,j++) {	\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,vec1);	\
      flgr2d_set_data_vector_##dtype(datdest,i,k,vec1);	\
    }							\
  }							\
  							\
  flgr_vector_destroy(vec1);				\
  return

void flgr2d_mirror_horizontal_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgBIT);
}
void flgr2d_mirror_horizontal_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgUINT8);
}
void flgr2d_mirror_horizontal_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgUINT16);
}
void flgr2d_mirror_horizontal_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgUINT32);
}
void flgr2d_mirror_horizontal_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgINT8);
}
void flgr2d_mirror_horizontal_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgINT16);
}
void flgr2d_mirror_horizontal_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgINT32);
}
void flgr2d_mirror_horizontal_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgFLOAT32);
}
void flgr2d_mirror_horizontal_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! mirror horizontally an image (regarding a vertical axis ...)
 *  @param datdest : a pointer to FLGR_Data2D
 *  @param datsrc  : a pointer to FLGR_Data2D
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_mirror_horizontal(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Ret ret;
  FLGR_DECLARE_FUNCTION;


  if((datdest == NULL) || (datsrc == NULL)) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  ret = flgr2d_is_data_same_attributes(datdest, datsrc, __FUNCTION__);
  if(ret != FLGR_RET_OK) return ret;
  

  FLGR_DISPATCH_PROCEDURE(datdest->type, flgr2d_mirror_horizontal, datdest, datsrc);
}












//////////////////////////////////////////////////////////////////
// macro for flgr2d_mirror_horizontal_hmorph
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(dtype)	\
  FLGR_Data2D *datdest = flgr2d_create_from(dat);;	\
  							\
  FLGR_DECLARE_FUNCTION;				\
							\
  flgr2d_mirror_horizontal_##dtype(datdest,dat);	\
  flgr2d_copy_##dtype##_##dtype(dat,datdest);		\
  flgr2d_destroy(datdest);				\
							\
  return

void flgr2d_mirror_horizontal_hmorph_fgBIT(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgBIT);
}
void flgr2d_mirror_horizontal_hmorph_fgUINT8(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgUINT8);
}
void flgr2d_mirror_horizontal_hmorph_fgUINT16(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgUINT16);
}
void flgr2d_mirror_horizontal_hmorph_fgUINT32(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgUINT32);
}
void flgr2d_mirror_horizontal_hmorph_fgINT8(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgINT8);
}
void flgr2d_mirror_horizontal_hmorph_fgINT16(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgINT16);
}
void flgr2d_mirror_horizontal_hmorph_fgINT32(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgINT32);
}
void flgr2d_mirror_horizontal_hmorph_fgFLOAT32(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgFLOAT32);
}
void flgr2d_mirror_horizontal_hmorph_fgFLOAT64(FLGR_Data2D *dat) {
  FLGR_MACRO_MIRROR2D_HORIZONTAL_HMORPH(fgFLOAT64);
}
//////////////////////////////////////////////////////////////////
/*! mirror horizontally an image (regarding a vertical axis ...)
 *  @param dat : a pointer to FLGR_Data2D
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_mirror_horizontal_hmorph(FLGR_Data2D *dat) {
  FLGR_DECLARE_FUNCTION;

  if(dat == NULL) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }


  FLGR_DISPATCH_PROCEDURE(dat->type, flgr2d_mirror_horizontal_hmorph, dat);
}





//////////////////////////////////////////////////////////////////
/*! Mirror with a horizontal centered axis a FLGR_Data2D array.
 *  Works in place
 *  @param *dat : pointer to FLGR_Data2D structure
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_mirror_vertical_hmorph(FLGR_Data2D *dat) {
  FLGR_Data1D *row_tmp;
  void *tmp;
  int i,j;

  FLGR_DECLARE_FUNCTION;

  if(dat==NULL) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  for(i=0,j=dat->size_y-1; i<dat->size_y/2 ; i++,j--) {
    tmp=dat->array[i];
    dat->array[i]=dat->array[j];
    dat->array[j]=tmp;

    row_tmp = dat->row[i];
    dat->row[i] = dat->row[j];
    dat->row[j] = row_tmp;

    dat->row[i]->ref2d=i;
    dat->row[j]->ref2d=j;

  }

  return FLGR_RET_OK;
}



//////////////////////////////////////////////////////////////////
/*! Mirror with a horizontal centered axis a FLGR_Data2D array.
 *  @param *datsrc : pointer to FLGR_Data2D structure
 *  @param *datdest : pointer to FLGR_Data2D structure
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_mirror_vertical(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Ret ret;
  FLGR_DECLARE_FUNCTION;


  if((datdest==NULL) || (datsrc==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  if((ret=flgr2d_copy(datdest,datsrc))!=FLGR_RET_OK) return ret;
  return flgr2d_mirror_vertical_hmorph(datdest);
}









//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_FILL_NHB_EVEN_ROWS(dtype)				\
  int mid=datsrc->size_y/2;						\
  int h=datsrc->size_y;							\
  int w=datsrc->size_x;							\
  int i,j;								\
  FLGR_Vector *tmp = flgr_vector_create(datsrc->spp,datsrc->type);	\
  FLGR_DECLARE_FUNCTION;						\
									\
									\
  for(i=mid ; i>=0 ; i-=2) {						\
    for(j=0;j<w;j++) {							\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j, tmp);			\
    }									\
  }									\
									\
  for(i=mid-1 ; i>=0 ; i-=2) {						\
    for(j=0;j<w-1;j++) {						\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j+1,tmp);		\
    }									\
    flgr2d_get_data_vector_##dtype(datsrc,i,w-1,tmp);			\
    flgr2d_set_data_vector_##dtype(datdest,i,0,tmp);			\
  }									\
									\
  for(i=mid+1 ; i<h ; i+=2) {						\
    for(j=0;j<w-1;j++) {						\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j+1,tmp);		\
    }									\
    flgr2d_get_data_vector_##dtype(datsrc,i,w-1,tmp);			\
    flgr2d_set_data_vector_##dtype(datdest,i,0,tmp);			\
  }									\
									\
  for(i=mid+2 ; i<h ; i+=2) {						\
    for(j=0;j<w;j++) {							\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j,tmp);			\
    }									\
  }									\
									\
  flgr_vector_destroy(tmp);						\
									\
  return


void flgr2d_fill_nhb_even_rows_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgBIT);
}
void flgr2d_fill_nhb_even_rows_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgUINT8);
}
void flgr2d_fill_nhb_even_rows_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgUINT16);
}
void flgr2d_fill_nhb_even_rows_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgUINT32);
}
void flgr2d_fill_nhb_even_rows_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgINT8);
}
void flgr2d_fill_nhb_even_rows_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgINT16);
}
void flgr2d_fill_nhb_even_rows_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgINT32);
}
void flgr2d_fill_nhb_even_rows_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgFLOAT32);
}
void flgr2d_fill_nhb_even_rows_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_EVEN_ROWS(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! fill a nhb definition from datsrc for processing correctly even rows in 6-connexity operations.
 *  @param *datsrc : pointer to neighborhood definition for odd rows processing
 *  @param *datdest : pointer to neighborhood definition for even rows processing
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_fill_nhb_even_rows(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((datsrc==NULL) || (datdest==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  ret=flgr2d_is_data_same_attributes(datdest,datsrc,__FUNCTION__);
  if(ret != FLGR_RET_OK) return ret;

  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_fill_nhb_even_rows,datdest,datsrc);
}


//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
#define FLGR_MACRO_FILL_NHB_ODD_ROWS(dtype)				\
  int mid=datsrc->size_y/2;						\
  int h=datsrc->size_y;							\
  int w=datsrc->size_x;							\
  int i,j;								\
  FLGR_Vector *tmp = flgr_vector_create(datsrc->spp,datsrc->type);	\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  for(i=mid ; i>=0 ; i-=2) {						\
    for(j=0;j<w;j++) {							\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j, tmp);			\
    }									\
  }									\
									\
  for(i=mid-1 ; i>=0 ; i-=2) {						\
    for(j=0;j<w-1;j++) {						\
      flgr2d_get_data_vector_##dtype(datsrc,i,j+1,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j,tmp);			\
    }									\
    flgr2d_get_data_vector_##dtype(datsrc,i,0,tmp);			\
    flgr2d_set_data_vector_##dtype(datdest,i,w-1,tmp);			\
  }									\
									\
  for(i=mid+1 ; i<h ; i+=2) {						\
    for(j=0;j<w-1;j++) {						\
      flgr2d_get_data_vector_##dtype(datsrc,i,j+1,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j,tmp);			\
    }									\
    flgr2d_get_data_vector_##dtype(datsrc,i,0,tmp);			\
    flgr2d_set_data_vector_##dtype(datdest,i,w-1,tmp);			\
  }									\
									\
  for(i=mid+2 ; i<h ; i+=2) {						\
    for(j=0;j<w;j++) {							\
      flgr2d_get_data_vector_##dtype(datsrc,i,j,tmp);			\
      flgr2d_set_data_vector_##dtype(datdest,i,j,tmp);			\
    }									\
  }									\
									\
  flgr_vector_destroy(tmp);						\
  return

void flgr2d_fill_nhb_odd_rows_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgBIT);
}
void flgr2d_fill_nhb_odd_rows_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgUINT8);
}
void flgr2d_fill_nhb_odd_rows_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgUINT16);
}
void flgr2d_fill_nhb_odd_rows_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgUINT32);
}
void flgr2d_fill_nhb_odd_rows_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgINT8);
}
void flgr2d_fill_nhb_odd_rows_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgINT16);
}
void flgr2d_fill_nhb_odd_rows_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgINT32);
}
void flgr2d_fill_nhb_odd_rows_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgFLOAT32);
}
void flgr2d_fill_nhb_odd_rows_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_MACRO_FILL_NHB_ODD_ROWS(fgFLOAT64);
}

//////////////////////////////////////////////////////////////////
/*! fill a nhb definition from datsrc for processing correctly odd rows in 6-connexity operations.
 *  @param *datsrc : pointer to neighborhood definition for odd rows processing
 *  @param *datdest : pointer to neighborhood definition for even rows processing
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_fill_nhb_odd_rows(FLGR_Data2D *datdest, FLGR_Data2D *datsrc) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((datsrc==NULL) || (datdest==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }

  ret=flgr2d_is_data_same_attributes(datdest,datsrc,__FUNCTION__);
  if(ret != FLGR_RET_OK) return ret;

  FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_fill_nhb_odd_rows,datdest,datsrc);
}


//////////////////////////////////////////////////////////////////
/*! Prepare an Even and Odd Neighborhood definition to slide on the image.<BR>
 *  If the nhb source is not 6-connex nhbEven and nhbodd will be copied from the
 *  the source definition regarding the SYM flag.<BR>The SYM flag allow the user
 *  to symetrize destinations neighborhoods regarding the center value.
 *  @param *nhbEven : pointer to FLGR_Data2D structure Even (destination)
 *  @param *nhbOdd : pointer to FLGR_Data2D structure Odd (destination)
 *  @param *nhb : pointer to FLGR_Data2D structure (source)
 *  @param *SYM : Flag (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr2d_fill_nhbs_for_6_connexity(FLGR_Data2D *nhbEven, FLGR_Data2D *nhbOdd, FLGR_Data2D *nhb, int SYM) {
  FLGR_Ret ret;

  FLGR_DECLARE_FUNCTION;

  if((nhb==NULL) || (nhbOdd==NULL) || (nhbEven==NULL)) {
    POST_ERROR("Null objects!\n");
    return FLGR_RET_NULL_OBJECT;
  }


  if((ret=flgr2d_is_data_same_attributes(nhbEven,nhbOdd,__FUNCTION__))!=FLGR_RET_OK) {
    return ret;
  }

  if((ret=flgr2d_is_data_same_attributes(nhbEven,nhb,__FUNCTION__))!=FLGR_RET_OK) {
    return ret;
  }

  if(SYM==FLGR_NHB_SYM) {
    if(flgr2d_data_is_connexity(nhb,FLGR_6_CONNEX)==FLGR_TRUE) {
      flgr2d_mirror_horizontal(nhbOdd,nhb);
      flgr2d_mirror_vertical_hmorph(nhbOdd);
      flgr2d_fill_nhb_even_rows(nhbEven,nhbOdd);
    }else {
      flgr2d_mirror_horizontal(nhbEven,nhb);
      flgr2d_mirror_vertical_hmorph(nhbEven);
      flgr2d_copy(nhbOdd,nhbEven);
    }
  }else {
    if(flgr2d_data_is_connexity(nhb,FLGR_6_CONNEX)==FLGR_TRUE) {
      flgr2d_copy(nhbEven,nhb);
      flgr2d_fill_nhb_odd_rows(nhbOdd,nhbEven);
    }else {
      flgr2d_copy(nhbEven,nhb);
      flgr2d_copy(nhbOdd,nhb);
    }
  }

  return FLGR_RET_OK;
}



//! @}

